/**
 * @file     maximumCount.js
 * @brief    [2529. 正整数和负整数的最大计数](https://leetcode.cn/problems/maximum-count-of-positive-integer-and-negative-integer/description/)
 * @author   Zhu
 * @date     2024-11-27 14:49
 */

/**
 * @param {number[]} nums
 * @return {number}
 */
var maximumCount = function (nums) {
    const n = nums.length;
    var lte = function (target) {
        let i = 0,
            j = n; // note `n`, not `n-1`
        while (i < j) {
            const mid = (i + j) >> 1;
            if (nums[mid] >= target) {
                j = mid;
            } else {
                i = mid + 1;
            }
        }
        return i;
    };

    const neg = lte(0);
    const pos = lte(1);
    return Math.max(neg, n - pos);
};

// maximumCount([-3, -2, -1, 0, 0, 1, 2])
